package itdep.common.resolver;

import itdep.common.services.EntityService;

/**
 * @author Ivan Khalopik
 * @version $Revision: 4 $ $Date: 2010-06-10 13:13:16 +0000 (Thu, 10 Jun 2010) $
 */
public class ServiceStringResolver<S extends EntityService> implements Resolver<String, S> {
	private final Resolver<Class<?>, S> serviceResolver;

	public ServiceStringResolver(final Resolver<Class<?>, S> serviceResolver) {
		this.serviceResolver = serviceResolver;
	}

	public S resolve(final String key) {
		return serviceResolver.resolve(coerceStringToClass(key));
	}

	protected Class<?> coerceStringToClass(final String key) {
		try {
			return Class.forName(key);
		} catch (ClassNotFoundException e) {
			return null;
		}
	}
}
